package com.cyt.web.controller.work.enrollment;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.SysUser;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.enrollment.model.vo.EnrollmentRuleVo;
import com.cyt.work.enrollment.service.EnrollmentRuleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自主招生-招生章程控制层
 *
 * @author caideyong
 * @date 2019-11-22 16:21:03
 */
@RestController
public class EnrollmentRuleController extends BaseController {

    @Resource
    private EnrollmentRuleService enrollmentRuleService;

    /**
     * 统一跳转
     *
     * @param pageName 页面名称
     * @param applyId  应用id
     * @return ModelAndView
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @RequestMapping("/enrollment/enrollmentrule/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId) {
        ModelAndView view = new ModelAndView("/work/enrollment/enrollmentrule/" + pageName);
        view.addObject("applyId", applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param enrollmentRuleVo 接受参数对象
     * @param page             当前页面
     * @param limit            页面数量
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/page", method = RequestMethod.POST)
    public ReturnResult page(EnrollmentRuleVo enrollmentRuleVo, int page, int limit) {
        return enrollmentRuleService.page(enrollmentRuleVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(HttpServletRequest request, String id,String applyId) {
        ModelAndView view = new ModelAndView("/work/enrollment/enrollmentrule/enrollmentRuleEdit");
        SysUser sysUser = acceptCurrentUser(request);
        view.addObject("sysUser", sysUser);
        view.addObject("applyId", applyId);
        if (StringUtils.isNotBlank(id)) {
            view.addObject("enrollmentRule", enrollmentRuleService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 跳转详情界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "跳转详情界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/getDetail", method = RequestMethod.GET)
    public ModelAndView getDetail(HttpServletRequest request, String id) {
        ModelAndView view = new ModelAndView("/work/enrollment/enrollmentrule/enrollmentRuleDetail");
        SysUser sysUser = acceptCurrentUser(request);
        view.addObject("sysUser", sysUser);
        if (StringUtils.isNotBlank(id)) {
            view.addObject("enrollmentRule", enrollmentRuleService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request          请求对象
     * @param enrollmentRuleVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, EnrollmentRuleVo enrollmentRuleVo) {
        return enrollmentRuleService.addOrUpdate(enrollmentRuleVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request          请求对象
     * @param enrollmentRuleVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, EnrollmentRuleVo enrollmentRuleVo) {
        return enrollmentRuleService.remove(enrollmentRuleVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request          请求对象
     * @param enrollmentRuleVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-11-22 16:21:03
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, EnrollmentRuleVo enrollmentRuleVo) {
        return enrollmentRuleService.delete(enrollmentRuleVo, acceptCurrentUser(request));
    }

    /**
     * 数据导出
     *
     * @param enrollmentRuleVo 传入参数对象
     * @param response         响应对象
     * @return void
     * @author caideyong
     * @date 2019/11/27
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "数据导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/export", method = RequestMethod.POST)
    public void export(HttpServletResponse response, EnrollmentRuleVo enrollmentRuleVo) {
        enrollmentRuleService.export(response, enrollmentRuleVo);
    }

    /**
     * 导入招生章程
     * @author caideyong
     * @date 2019/11/27
     * @return ReturnResult
     */
    @BaseLog(module = "自主招生", classz = "招生章程", methods = "导入招生章程", businessType = BusinessType.IMPORT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/enrollment/enrollmentrule/importData", method = RequestMethod.POST)
    public ReturnResult importData(HttpServletRequest request, MultipartFile file, String catalog, String update, String applyId) {
        return enrollmentRuleService.importData(request, file, catalog, update, applyId, acceptCurrentUser(request));
    }
}